package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IAiTagService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.AiTagCreateValidate;
import com.mdd.admin.validate.AiTagUpdateValidate;
import com.mdd.admin.validate.AiTagSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.AiTagListedVo;
import com.mdd.admin.vo.AiTagDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/aiTag")
@Api(tags = "ai标签管理")
public class AiTagController {

    @Resource
    IAiTagService iAiTagService;

    @GetMapping("/list")
    @ApiOperation(value="ai标签列表")
    public AjaxResult<PageResult<AiTagListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated AiTagSearchValidate searchValidate) {
        PageResult<AiTagListedVo> list = iAiTagService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="ai标签详情")
    public AjaxResult<AiTagDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        AiTagDetailVo detail = iAiTagService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "ai标签新增")
    @PostMapping("/add")
    @ApiOperation(value="ai标签新增")
    public AjaxResult<Object> add(@Validated @RequestBody AiTagCreateValidate createValidate) {
        iAiTagService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "ai标签编辑")
    @PostMapping("/edit")
    @ApiOperation(value="ai标签编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody AiTagUpdateValidate updateValidate) {
        iAiTagService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "ai标签删除")
    @PostMapping("/del")
    @ApiOperation(value="ai标签删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iAiTagService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
